-
Notifications
You must be signed in to change notification settings - Fork 4
Implement VotingStreakMultiplier #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs slight redesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pattern is implemented as expected! looking very elegant!
@bagelface @RonTuretzky with my latest commit here, the build is compiling without errors/warnings and the tests all pass. Can you advise on next steps? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so far , please add a VotingStreakMultiplier.t.sol
file with unit tests
@RonTuretzky @bagelface Can you advise now on next steps? |
function mint(address receiver) external payable virtual; | ||
} | ||
|
||
contract VotingStreakMultiplierTest is Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a Voting multiplier testing section here , would probably be better to refactor this to extend that area
not gonna block this PR on that though tbh, thoughts @bagelface ?
Lets keep in mind this will all be refactored for breadkit anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i moved them to the yd 5376053
function test_multiplier_increment_after_3_subsequent_cycles() public { | ||
VotingStreakMultiplier multiplier = setUpVotingStreakMultiplier(); | ||
address testAccount = setUpTestAccount(); | ||
uint256 cycleIterator = 0; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
// Initial multiplier should be 0 | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), 0); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier was updated to multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), multiplier.multiplierIncrement()); | ||
assertEq( | ||
multiplier.validUntil(testAccount), | ||
yieldDistributor.lastClaimedBlockNumber() + 2 * yieldDistributor.cycleLength() | ||
); | ||
|
||
// Roll to the next cycle | ||
cycleIterator++; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier was updated to 2 * multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), 2 * multiplier.multiplierIncrement()); | ||
|
||
// Roll to the next cycle | ||
cycleIterator++; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier was updated to 3 * multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), 3 * multiplier.multiplierIncrement()); | ||
} | ||
|
||
// when the account has voted in 4 subsequent cycles, the account's multiplier is equal to maxMultiplier | ||
function test_multiplier_increment_after_4_subsequent_cycles() public { | ||
VotingStreakMultiplier multiplier = setUpVotingStreakMultiplier(); | ||
address testAccount = setUpTestAccount(); | ||
uint256 cycleIterator = 0; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
// Initial multiplier should be 0 | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), 0); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier was updated to multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), multiplier.multiplierIncrement()); | ||
assertEq( | ||
multiplier.validUntil(testAccount), | ||
yieldDistributor.lastClaimedBlockNumber() + 2 * yieldDistributor.cycleLength() | ||
); | ||
|
||
// Roll to the next cycle | ||
cycleIterator++; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier was updated to 2 * multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), 2 * multiplier.multiplierIncrement()); | ||
|
||
// Roll to the next cycle | ||
cycleIterator++; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier was updated to 3 * multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), 3 * multiplier.multiplierIncrement()); | ||
|
||
// Roll to the next cycle | ||
cycleIterator++; | ||
setUpForCycle(yieldDistributor, cycleIterator); | ||
|
||
castVote(testAccount); | ||
|
||
// Verify multiplier does not exceed maxMultiplier * multiplierIncrement | ||
assertEq(multiplier.getMultiplyingFactor(testAccount), MAX_MULTIPLIER * MULTIPLIER_INCREMENT); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should be removed in favor of a fuzz test
You can reference the two tests here for how you can turn a vanilla test into a fuzz test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thats neat! thanks for the tip.
replaced those tests with a fuzz test fe64fc6
When a vote is cast (via the YieldDistributor), the VotingStreakMultiplier updates it's state variables tracking user's multiplier value and validity.
When this contract is deployed, the front end can call
getMultiplyingFactor
for the user's current multiplier.